#include <stdio.h>
#include "stack.h"

int main() {
    _stack_t my_stack;
    int i = 0;

    stack_init(&my_stack, 5);  //初始化栈
    printf("进栈顺序\n");
    for(i = 0; i < 5; i++){
        printf("%d, ", i);
        stack_push(&my_stack, i);  //将数据压入栈
    }
    printf("\n");
    if(stack_is_full(&my_stack)){
        printf("栈已满\n");
    }else{
        printf("栈未满\n");
    }
    printf("栈的大小是：%d\n", stack_size(&my_stack));
    printf("出栈顺序是\n");
    for(i = 0; i < 5; i++){
        printf("%d ,", stack_pop(&my_stack));
    }
    printf("\n");
    if(stack_is_empty(&my_stack)){
        printf("栈为空\n");
    }else{
        printf("栈未空\n");
    }
    stack_destroy(&my_stack);  //销毁栈

    printf("\n\n");
    printf("用链表实现栈\n");
    printf("入栈顺序\n");
    printf("%d ,", 0);
    stack_linked_t *my_stack2 = new_stack_linked_node(0);
    for(i = 0; i < 5; i++){
        printf("%d ,", i + 1);
        stack_linked_push(&my_stack2, i + 1);
    }
    printf("\n");
    printf("栈大小是: %d\n", stack_linked_size(my_stack2));
    printf("出栈顺序是\n");
    for(i = 0; i < 6; i++){
        printf("%d ,", stack_linked_pop(&my_stack2));
    }
    printf("\n");
    if(stack_linked_is_empty(my_stack2)){
        printf("链栈为空\n");
    }else{
        printf("链栈非空\n");
    }
    stack_linked_destroy(&my_stack2);

    return 0;
}
